#!/bin/sh /etc/rc.common
# Copyright (C) 2017 OpenWrt.org

START=60

USE_PROCD=1

#PROCD_DEBUG=1

DAEMON=restund
DEFAULT=/etc/default/$DAEMON
LOGGER="/usr/bin/logger -p user.err -s -t $DAEMON"
OPTIONS=
PROG=/usr/sbin/$DAEMON

[ -f $DEFAULT ] && . $DEFAULT

start_service() {
  local dir=

  if [ "$ENABLE_RESTUND" != yes ]; then
    $LOGGER User configuration incomplete - not starting $DAEMON
    $LOGGER Check ENABLE_RESTUND in $DEFAULT
    exit 1
  fi

  procd_open_instance
  procd_set_param command $PROG
  procd_append_param command \
    -n \
    $OPTIONS
  procd_set_param pidfile /var/run/${DAEMON}.pid
  # forward stderr to logd
  procd_set_param stderr 1
  # forward stdout to logd
  procd_set_param stdout 1
  procd_set_param user $DAEMON
  procd_close_instance
}
